package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.StockOutComeBill;
import cn.wolfcode.crm.qo.PageResult;
import cn.wolfcode.crm.qo.StockOutcomeBillQueryObject;
import cn.wolfcode.crm.service.IStockOutcomeBillService;
import cn.wolfcode.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Optional;

@Controller
@RequestMapping("stockOut")
public class StockOutcomeBillController {

    @Autowired
    private IStockOutcomeBillService stockOutcomeBillService;


    @RequestMapping("view")
    public String view() {
        return "stockOutcomeBill/list";
    }


    @RequestMapping("query")
    @ResponseBody
    public PageResult query(StockOutcomeBillQueryObject qo) {
        PageResult result = stockOutcomeBillService.query(qo);
        return result;
    }


    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StockOutComeBill stockOutcomeBill) {

        try {
            if (Optional.ofNullable(stockOutcomeBill).isPresent()) {
                stockOutcomeBillService.saveOrUpdate(stockOutcomeBill);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.mark(e.getMessage());
        }
        return new JSONResult();
    }



    @RequestMapping("audit")
    @ResponseBody
    public Object audit(Long id) {
        try {
            if (Optional.ofNullable(id).isPresent()) {
                stockOutcomeBillService.audit(id);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.mark(e.getMessage());
        }
        return new JSONResult();
    }
}
